<template>
  <div class="app-container">
    <div class="searchBox">
      <el-form :inline="true" :model="search" ref="searchForm">
        <el-form-item label="选择类型：" prop="typeId">
          <el-select v-model="search.typeId">
            <el-option
              v-for="item in controlData.dictTypes"
              :key="item.typeId"
              :label="item.name"
              :value="item.typeId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="数据名称：" prop="name">
          <el-input v-model="search.name" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item label="数据编码：" prop="code">
          <el-input v-model="search.code" name="code" placeholder="请输入内容"></el-input>
        </el-form-item>
        <el-form-item style="margin-top: -2px">
          <el-button type="primary" @click="searchQuery">查询</el-button>
          <el-button type="info" @click="search = {};searchQuery()">重置</el-button>
        </el-form-item>
      </el-form>
    </div>

    <qm-table
      ref="qmTable"
      :data="query"
      keyProp="itemId"
      menuType="text"
      :formOptions="{ labelWidth: '120px' }"
      :rules="rules"
    >
      <qm-table-column field="name" sortable>数据名称</qm-table-column>
      <qm-table-column field="code" sortable>数据编码</qm-table-column>
      <qm-table-column field="isEnabled" fieldtype="enabledisable" sortable width="100px">是否启用</qm-table-column>

      <template #toolbar>
        <el-button type="primary" @click="showTreeView">树状视图</el-button>
      </template>

      <template v-slot:form="{ model, viewModel, controlData }">
        <el-row>
          <el-col :span="12">
            <el-form-item label="字典类型" prop="model.typeId">
              <el-select v-model="model.typeId">
                <el-option
                  v-for="item in controlData.dictTypes"
                  :key="item.typeId"
                  :label="item.name"
                  :value="item.typeId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="父级节点" prop="model.parentId">
              <el-select v-model="model.parentId">
                <el-option
                  v-for="item in controlData.items"
                  :key="item.itemId"
                  :label="item.name"
                  :value="item.itemId"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="数据名称：" prop="model.name">
              <el-input v-model="model.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="数据编码：" prop="model.code">
              <el-input v-model="model.code"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="排序编号：" prop="model.sort">
              <el-input v-model="model.sort"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="是否启用：" prop="model.isEnabled">
              <el-radio v-model="model.isEnabled" :label="true">是</el-radio>
              <el-radio v-model="model.isEnabled" :label="false">否</el-radio>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="预留字段1：" prop="model.reserved1">
              <el-input v-model="model.reserved1"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="预留字段2：" prop="model.reserved2">
              <el-input v-model="model.reserved2"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="扩展3：" prop="model.reserved3">
              <el-input v-model="model.reserved3"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <el-form-item label="备注：" prop="model.memo">
              <el-input type="textarea" v-model="model.memo"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row v-if="viewModel.pageAction === 'view'">
          <el-col :span="12">
            <el-form-item label="创建时间：" prop="model.createdDate">
              <el-date-picker type="datetime" v-model="model.createdDate" style="width: 100%"></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="更新时间：" prop="model.updatedDate">
              <el-date-picker type="datetime" v-model="model.updatedDate" style="width: 100%"></el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>
      </template>
    </qm-table>

    <get-tree v-model="treeVisible" :typeId="search.typeId" @cancel="treeVisible = false"></get-tree>
  </div>
</template>

<script>
import Controller from "@/libs/framework/controller";
import GetTree from "@/views/admin/sysDictItem/getTree";

export default class Instance extends Controller {
  onBeforeInit() {
    this.urls = {
      query: [{ url: "/admin/sysDictItem/query", method: "post" }],
      save: "/admin/sysDictItem/save",
      delete: "/admin/sysDictItem/delete",
      entity: "/admin/sysDictItem/getEntity",
    };
    this.urls.model = "/admin/sysDictItem/getListModel";
  }

  mixin() {
    return {
      components: {
        GetTree,
      },
      data() {
        return {
          treeVisible: false,
          rules: {
            model: {
              typeId: [
                {
                  required: true,
                  message: "请选择字典类型",
                  trigger: "blur",
                },
              ],
              name: [
                {
                  required: true,
                  message: "请输入字典名称",
                  trigger: "blur",
                },
              ],
              code: [
                {
                  required: true,
                  message: "请输入字典编码",
                  trigger: "blur",
                },
              ],

              isEnabled: [
                {
                  required: true,
                  message: "请选择是否启用",
                },
              ],
            },
          },
        };
      },
      methods: {
        showTreeView() {
          if (!this.search.typeId) {
            this.msgError("请先选择类型");
            return;
          }
          this.treeVisible = true;
        },
      },
    };
  }
}
</script>

<style scoped lang="scss">
</style>

